#include "bOS/bOS.h"
#include "bOS/bOSString.h"

#include "bOS/bOSXOR256Stream.h"
//using namespace bOS::Crypto;

#include "bOS/bOSFileSystem.h"
using namespace bOS::IO;

#include <iostream>

using namespace std;


//1- D=Decrypt E=Encrypt
//2- Key
//3- File
int main(int argc, char* argv[])
{
	if ( argc < 3 )
	{
		std::cout << "Parameter Error. [D|E] File" << std::endl;
		return 1;
	}
	

	bOS::CoreString::String sKey;

	std::cout << "Insert key: ";
	std::cin >> sKey;

	std::cout << std::endl;

	try
	{
		CXOR256Stream oRijndael;
		oRijndael.Initialize(sKey.c_str(), strlen(sKey.c_str()));

		bOS::CoreString::String sFileOut = argv[2];
		if ( ( strcmp(argv[1], "E") == 0 ) || ( strcmp(argv[1], "Encrypt") == 0 ) )
		{
			std::cout << "Encrypt " << argv[2] << " initiated" << std::endl;
			sFileOut+=".zz";
			oRijndael.EncryptFile(argv[2], sFileOut.c_str());
		}
		else
		{
			std::cout << "Decrypt" << argv[2] << "initiated" << std::endl;
			oRijndael.DecryptFile(argv[2], "zzDecryptedFile");
		}
	}
	catch(exception& roException)
	{
		std::cout << "Error " << roException.what() << std::endl;
	}
}
